class person:
    def __init__(self, name, age, weight, height):
        self.name = name
        self.age = age
        self.height = height
        self.weight = weight

    def run(self):
        self.weight -= 0.5
        print(f'{self.name}跑步了，体重减去0.5公斤,现有体重{self.weight}')

    def eat(self):
        self.weight += 1
        print(f'{self.name}吃饭了，体重增加1公斤,现有体重{self.weight}')

    def growup(self):
        self.age += 1
        self.height += 1
        print(f'{self.name}长大了，年龄增加1岁，身高增加1cm,现有身高为{self.height}，现在年龄为{self.age}')

    def __str__(self):
        return f'我的名字叫 {self.name} 体重 {self.weight}公斤 身高 {self.height}cm 年龄 {self.age} '


if __name__ == '__main__':
    elephant = person('大象', 80,50,170)
    elephant.run()
    elephant.eat()
    elephant.growup()
    print(elephant)
    tiger = person("老虎", 45,60,180)
    tiger.eat()
    tiger.run()
    tiger.growup()






class HouseItem:
    def __init__(self, name, area):
        """
        初始化方法
        :param name: 家具名字
        :param area: 家具占地面积
        """
        self.name = name
        self.area = area

    def __str__(self):
        return "[%s] 占地 %.2f" % (self.name, self.area)


class House:
    def __init__(self, house_type, area):
        self.house_type = house_type
        self.area = area
        self.free_area = area  # 剩余可用面积
        self.items_list = []  # 家具列表

    def __str__(self):
        return ("户型：%s\n总面积：%.2f[剩余：%.2f]\n家具：%s"
                % (self.house_type, self.area,
                   self.free_area, self.items_list))

    def add_item(self, item:HouseItem):               #通过冒号:对象类型,加注解,可以不加
        if item.area>self.free_area:
            print('房子没空间了，放家具失败')
            return
        # 2. 计算剩余面积
        self.free_area-=item.area
        # 3. 将家具的名称追加到名称列表中
        self.items_list.append(item.name)


if __name__ == '__main__':
    bed = HouseItem('席梦思', 4)
    chest = HouseItem("衣柜", 2)
    table = HouseItem("餐桌", 1.5)
    print(bed)
    print(chest)
    print(table)
    house=House("二室一厅", 30)
    house.add_item(bed)
    house.add_item(chest)
    house.add_item(table)
    print(house)




print('-'*50)
print('下一题')
print('-'*50)



class Women:
    def __init__(self, name, age):
        self.name = name
        self.__age = age

    def __secret(self):
        print(f'{self.name} 年龄{self.__age}')

    def boy_friend(self):
        self.__secret()


if __name__ == '__main__':
    xiaohong = Women('小红', 18)
    xiaohong.boy_friend()
    print(xiaohong.__dict__)   #这句咋理解老师        ？？？？？？？？
    # print(xiaohong.__age)   私有属性无法直接访问，必须通过类方法
    # xihong.__secret()      私有方法无法直接访问，必须通过类内方法，别的类的方法也不行
    # print(xiaohong._Women__age)  不这么写



print('-'*50)
print('下一题')
print('-'*50)



class Animal:

    def __init__(self, name):
        self.name = name

    def eat(self):
        print("吃---")

    def drink(self):
        print("喝---")

    def run(self):
        print("跑---")

    def sleep(self):
        print("睡---")


class Dog(Animal):
    def __init__(self, name, color):
        super().__init__(name)  # 子类对象调用父亲的init
        self.color = color

    def bark(self):
        print(f'{self.name}汪汪叫{self.color}--')

    def run(self):
        super().run()
        print(f'{self.name}跑的快')


class XiaoTianQuan(Dog):
    def __init__(self, name, color, age):
        super().__init__(name, color)
        self.age = age

    def fly(self):
        print(f'{self.name}飞天--{self.color}--{self.age}')


if __name__ == '__main__':
    wangcai = Dog('旺财', '黄色')
    wangcai.bark()
    wangcai.run()
    xiaotianquan = XiaoTianQuan('哮天犬', '黑色', 20)
    xiaotianquan.fly()



class A:
    def test(self):
        print('A test')

    def demo(self):
        print('A demo')


class B:
    def test(self):              #可以用*args,也可以不用，对于继承的c来说访问结果不变，按顺序吃下元素
        print('B test')

    def demo(self):
        print('B demo')


class C(A, B):
    def test(self):
        print('C test')


if __name__ == '__main__':
    c = C()
    c.test()
    print(C.__mro__)      #打印访问顺序
# 多重继承先父叔伯，再爷爷






print('-'*50)
print('下一题')
print('-'*50)








class MusicPlayer(object):
    instance = None  # 用来保存对象的

    def __new__(cls, *args, **kwargs):
        if cls.instance is None:
            cls.instance=super().__new__(cls)  #父亲的new类似于C的malloc
        return cls.instance

    def __init__(self,name):
        self.name=name

if __name__ == '__main__':
    player1 = MusicPlayer('七里香')
    player2 = MusicPlayer('东风破')
    print(id(player1))
    print(id(player2))
    print(player1.name)
    print(player2.name)




print('-'*50)
print('下一题')
print('-'*50)







def input_password():

    # 1. 提示用户输入数字
    num = input("请输入数字：")

    # 2. 判断数字是否为整形数
    try:
        if int(num):
            print('输入成功')
            if num[::1]==num[::-1]:
                print('f{num}是对称数')
            else:
                raise Exception("输入的不是对称数")
    except ValueError:
        print('输入的不是数字')
    except Exception as result:
        print(result)

# input_password()